#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <cstring>
using namespace std;
void showpending()
{
    sigset_t set;
    sigpending(&set);
    for (int i = 1; i <= 31; i++)
    {
        if (sigismember(&set, i))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << endl;
}

void handle(int signo)
{
    cout<<signo<<endl;  
  // sleep(10);
    int cnt = 30;
    while (cnt--)
    {
        sleep(1);
        showpending();
    }

    cout << "处理信号:" << signo << endl;
}

int main()
{
    cout << "pid为" << getpid() << endl;
    sigset_t set;
    sigaddset(&set, 3);
    sigaddset(&set, 4);
    sigaddset(&set, 5);
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_handler = handle;
    act.sa_mask = set;
    struct sigaction oact;
    memset(&oact, 0, sizeof(oact));
    sigaction(2, &act, &oact);
    while (true)
    {
        // sleep(1);
        // showpending();
    }

    return 0;
}
